<!doctype html>
<html class="no-js">
<head>
    <meta charset="UTF-8">
    <title>用户列表 | 校园知事</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/x-icon" href="/favicon.ico">
    <link rel="stylesheet" href="/assets/css/amazeui.min.css" />
    <link rel="stylesheet" href="/assets/css/admin.css">
    <link rel="stylesheet" href="/assets/css/appadmin.css"></head>
<body>
   {{template "admin/naver.html" .}}
    <!-- content start -->
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf">
                    <div class="am-g">
                        <div class="am-u-md-4 am-u-sm-12"> <strong class="am-text-primary am-text-lg"  style=" color: #222222;">管理员列表</strong>
                        </div>
                        <div class="am-u-sm-12 am-u-md-6">
                            <div class="am-input-group am-input-group-sm">
                                <input type="text" class="am-form-field" placeholder="姓名" id="mult" maxlength="20" >
                                <span class="am-input-group-btn">
                                    <button class="am-btn am-btn-default" type="button" onclick="search()">搜索</button>
                                </span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <hr>
            <div class="am-g">
                <div class="am-u-sm-12">
                    <table class="am-table am-table-striped am-table-hover table-main">
                        <thead>
                            <tr>
                                <th class="table-id">编号</th>
                                <th class="table-title">账号</th>
                                <th class="table-type">姓名</th>
                                <th class="table-author am-hide-sm-only">手机号码</th>
                                <th class="table-date am-hide-md-down">邮箱</th>
                                <th class="table-set">操作</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                    <div class="am-cf">
                        <div id="pageNav" style="text-align:center"></div>
                        <p class="am-margin-top-sm" id="msg"></p>
                    </div>
                </div>
            </div>
        </div>
    </div>
    {{template "admin/footer.html" .}}
    <script src="/assets/laypage/laypage.js"></script>
    <script type="text/javascript">
     document.onkeydown=function(event){
            var e = event || window.event || arguments.callee.caller.arguments[0];
             if(e && e.keyCode==13){
                search();
            }
        };
        $(function(){
            _init(1,8);
        })
        function _init(pi,ps){
            $.AMUI.progress.start();
            $.post("/admin/user/list",{s:pi,c:ps,n:$("#mult").val().trim()},function(data){
                if(data.status===1&&data.count>0){
                    var list='';
                    $.each(data.data,function(k,v){
                        list+='<tr><td>'+(k+1)+'</td>';
                        list+='<td>'+v.Num+'</td>';
                        list+='<td>'+v.Username+'</td>';
                        list+='<td class="am-hide-sm-only">'+v.Phone+'</td>';
                        list+='<td class="am-hide-md-down">'+v.Email+'</td>';
                        list+='<td><div class="am-btn-toolbar"><div class="am-btn-group am-btn-group-xs">';
                        list+='<button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="javascript:window.location.href=\'/admin/user/edit/'+v.Id+'\'"><span class="am-icon-pencil-square-o"></span> 编辑</button>';
                        list+='<button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="reset('+v.Id+')" ><span class="am-icon-retweet"></span> 重置</button> ';
                        if (v.Status===0) {
  list+='<button class="am-btn am-btn-default am-btn-xs am-hide-md-down"  onclick="disable('+v.Id+','+1+')" ><span class="am-icon-times"></span> 禁用</button> ';
                        }else{
  list+='<button class="am-btn am-btn-default am-btn-xs am-hide-md-down"  onclick="disable('+v.Id+','+0+')" ><span class="am-icon-times"></span> 启用</button> ';
                        }

                        list+='<button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-md-down"  onclick="del('+v.Id+')" ><span class="am-icon-trash-o"></span> 删除</button></div> </div> </td> </tr>';
                    });
                    $("tbody").html(list);
                     laypage({
                        cont: $('#pageNav'),
                        pages: Math.ceil(data.count / ps),
                        curr: pi || 1,
                        skip: false,
                        jump: function (obj, first) {
                             $('#msg').html('注：第'+obj.curr+'/'+obj.pages+'页&nbsp;&nbsp;&nbsp;(共'+data.count +'条)');
                            if (!first) {
                                _init(obj.curr, ps);
                            }
                        }
                    });
                }else{
 				$("tbody").html('');
				$('#pageNav').html('未查询到相关信息');
                $('#msg').html('');
				}
            $.AMUI.progress.done();
            },"json")
        }
        function search(){
            _init(1,8);
        }
        function del(i){
           var l= layer.confirm('你确定要删除吗？',{icon: 3, title:'警告',offset:'15%'},function(){
                layer.close(l);
                $.lintul('/admin/user/deleteone',{id:i},function(data){
                 if (data.status === 1) {
                        layer.msg('删除成功', { offset: '15%', icon: 6 ,time:1000}, function () {
                            _init(1,8);
                        });
                    } else {
                        layer.msg('删除失败,请检查后重试', { offset: '15%', icon: 5 });
                    }
            });
            });
        }
        function disable(i,s){
            var str='你确定要禁用此账户吗？'
            if (s===0){
                str='你确定要启用此账户吗？'
            }
            var l= layer.confirm(str,{icon: 3, title:'警告',offset:'15%'},function(){
             layer.close(l);
             $.lintul('/admin/user/fbd',{id:i,fbd:s},function(data){
                 if (data.status === 1) {
                        layer.msg('状态改变成功', { offset: '15%', icon: 6 ,time:1000}, function () {
                            _init(1,8);
                        });
                    } else {
                        layer.msg('状态改变失败,请检查后重试', { offset: '15%', icon: 5 });
                    }
            });
            });

        }
        function reset(i){
            var l= layer.confirm('你确定要重置密码为123456吗？',{icon: 3, title:'警告',offset:'15%'},function(){
              layer.close(l);
               $.lintul('/admin/user/cpo',{id:i},function(data){
                 if (data.status === 1) {
                        layer.msg('密码重置成功', { offset: '15%', icon: 6 ,time:1000}, function () {
                            _init(1,8);
                        });
                    } else {
                        layer.msg('密码重置失败,请检查后重试', { offset: '15%', icon: 5 });
                    }
            });
            });

        }
    </script>
</body>
</html>
